const Sequelize = require('sequelize')
const sequelize = require('../config/index')

let User = sequelize.define('user', {
        // 指定映射的字段类型，字段名，例如数据库中 user 表中的 username 字段映射成 username
        uid:{
            type: Sequelize.INTEGER,
            field: 'uid',
            primaryKey:true,
            autoIncrement: true,
            comment: "主键，自增"
        },
        livestatu:{
            type:Sequelize.STRING,
            defaultValue:0,
            comment:'当前状态 0 普通用户 1企业用户'
        },
        openid:{
            type: Sequelize.STRING,
            comment:"用户的唯一标识"
        },
        nickname:{
            type:Sequelize.STRING,
            comment:"用户昵称",
            defaultValue: null
        },
        sex:{
            type: Sequelize.INTEGER,
            defaultValue:0,
            comment:'户的性别，值为1时是男性，值为2时是女性，值为0时是未知'
        },

        country:{
            type:Sequelize.STRING,
            comment:"国家，如中国为CN",
            defaultValue: null

        },
        headimgurl:{
            type:Sequelize.STRING,
            comment:"headimgurl",
            defaultValue: null

        },
        unionid:{
            type: Sequelize.STRING,
            comment:'只有在用户将公众号绑定到微信开放平台帐号后，才会出现该字段。',
            defaultValue:null
        },
        access_token:{
            type: Sequelize.STRING,
            comment:'用户授权秘钥'
        },
        username: {
            type: Sequelize.STRING,
            field: 'username',
            comment:'用户名'
        },
        isVerify:{
            type: Sequelize.INTEGER,
            defaultValue:0,
            comment:'认证状态,0未认证，1已认证'
        },
        balance:{
            type: Sequelize.INTEGER,
            defaultValue:0,
            comment:'余额'
        },
        isDel:{
            type: Sequelize.INTEGER,
            defaultValue:0,
            comment:'状态，是否删除'
        },
        ban:{
            type: Sequelize.INTEGER,
            defaultValue:0,
            comment:'是否封禁'
        }

    },
    {
        // freezeTabelName 为 true 时不会在库中映射表时增加复数表名
        // 该选项为 true 时，user 在映射时映射成 user，而为 false 时会映射成users
        freezeTableName: false,

    });

/**
 * 用户信息
 */
let UserInfo= sequelize.define('user_info',{
    id:{
        type:Sequelize.INTEGER,
        primaryKey: true,
        autoIncrement: true,
        comment:'id',
    },
    name:{
        type:Sequelize.STRING,
        comment:'姓名',
    },
    age:{
        type:Sequelize.STRING,
        comment:'年龄',
    },
    sex:{
        type:Sequelize.STRING,
        defaultValue:0,
        comment:'性别',
    },
    school:{
        type:Sequelize.STRING,
        comment:'学校',
    },
    asm:{
        type:Sequelize.STRING,
        comment:'自我评价',
    },
    subtitle:{
        type:Sequelize.STRING,
        comment:'签名',
    },

    wx_pay_no:{
        type:Sequelize.STRING,
        comment:'微信账号',
    },
    ali_pay_no:{
        type:Sequelize.STRING,
        comment:'阿里账号',
    },
    email:{
        type:Sequelize.STRING,
        comment:'邮箱',
    },
    phone:{
        type:Sequelize.STRING,
        comment:'电话',
    },
    isDel:{
        type:Sequelize.INTEGER,
        defaultValue:0,
        comment:'是否已删除'
    },
},{
    // freezeTabelName 为 true 时不会在库中映射表时增加复数表名
    // 该选项为 true 时，user 在映射时映射成 user，而为 false 时会映射成users
    freezeTableName: true,

})
/**
 * 用户信息
 */
let User_info_pre= sequelize.define('user_info_pre',{
    id:{
        type:Sequelize.INTEGER,
        primaryKey: true,
        autoIncrement: true,
        comment:'id',
    },
    info:{
        type:Sequelize.STRING,
        defaultValue:0,
        comment:'我的信息'
    },
    preference:{
        type:Sequelize.STRING,
        defaultValue:0,
        comment:'偏好设置'
    },
    education:{
        type:Sequelize.STRING,
        defaultValue:0,
        comment:'偏好设置'
    },
    skill:{
        type:Sequelize.STRING,
        defaultValue:0,
        comment:'作品与技能'
    },
    job:{
        type:Sequelize.STRING,
        defaultValue:0,
        comment:'工作经历'
    },

    isDel:{
        type:Sequelize.STRING,
        defaultValue:0,
        comment:'是否已删除'
    },
},{
    // freezeTabelName 为 true 时不会在库中映射表时增加复数表名
    // 该选项为 true 时，user 在映射时映射成 user，而为 false 时会映射成users
    freezeTableName: true,

})
/**
 * 教育背景
 */
let Education_bg= sequelize.define('education_bg',{
    id:{
        type:Sequelize.INTEGER,
        primaryKey: true,
        autoIncrement: true,
        comment:'id',
    },
    school:{
        type:Sequelize.TEXT,
        comment:'学校'
    },
    speciality:{
        type:Sequelize.TEXT,
        comment:'专业'
    },
    academic:{
        type:Sequelize.TEXT,
        comment:'学历'
    },
    honor:{
        type:Sequelize.TEXT,
        comment:'荣誉'
    },
    isDel:{
        type:Sequelize.INTEGER,
        defaultValue:0,
        comment:'是否已删除'
    },
},{
    // freezeTabelName 为 true 时不会在库中映射表时增加复数表名
    // 该选项为 true 时，user 在映射时映射成 user，而为 false 时会映射成users
    freezeTableName: true,
})
/**
 * 工作经历
 */
let Job= sequelize.define('job',{
    id:{
        type:Sequelize.INTEGER,
        primaryKey: true,
        autoIncrement: true,
        comment:'id',
    },
    company:{
        type:Sequelize.STRING,
        comment:'公司'
    },
    start_time:{
        type:Sequelize.STRING,
        comment:'起始时间'
    },
    end_time:{
        type:Sequelize.STRING,
        comment:'结束时间'
    },
    position:{
        type:Sequelize.STRING,
        comment:'职位'
    },
    address:{
        type:Sequelize.TEXT,
        comment:'工作地点'
    },
    des:{
        type:Sequelize.TEXT,
        comment:'补充说明'
    },
    isDel:{
        type:Sequelize.STRING,
        defaultValue:0,
        comment:'是否已删除'
    },
},{
    // freezeTabelName 为 true 时不会在库中映射表时增加复数表名
    // 该选项为 true 时，user 在映射时映射成 user，而为 false 时会映射成users
    freezeTableName: true,
})
/**
 * 工作经历
 */
let Skill= sequelize.define('skill',{
    id:{
        type:Sequelize.INTEGER,
        primaryKey: true,
        autoIncrement: true,
        comment:'id',
    },
    name:{
        type:Sequelize.STRING,
        comment:'技能名称'
    },
    level:{
        type:Sequelize.INTEGER,
        comment:'技能熟练度'
    },
    isDel:{
        type:Sequelize.STRING,
        defaultValue:0,
        comment:'是否已删除'
    },
},{
    // freezeTabelName 为 true 时不会在库中映射表时增加复数表名
    // 该选项为 true 时，user 在映射时映射成 user，而为 false 时会映射成users
    freezeTableName: true,
})
/**
 * 作品
 */
let Opus= sequelize.define('opus',{
    id:{
        type:Sequelize.INTEGER,
        primaryKey: true,
        autoIncrement: true,
        comment:'id',
    },
    name:{
        type:Sequelize.STRING,
        comment:'作品名称'
    },
    des:{
        type:Sequelize.TEXT,
        comment:'作品描述/简介'
    },
    links:{
        type:Sequelize.STRING,
        comment:'作品链接'
    },
    image1:{
        type:Sequelize.TEXT,
        comment:'作品图片1'
    },
    image2:{
        type:Sequelize.TEXT,
        comment:'作品图片2'
    },
    isDel:{
        type:Sequelize.STRING,
        defaultValue:0,
        comment:'是否已删除'
    },
},{
    // freezeTabelName 为 true 时不会在库中映射表时增加复数表名
    // 该选项为 true 时，user 在映射时映射成 user，而为 false 时会映射成users
    freezeTableName: true,
})
/**
 * 账单
 */
let Bills= sequelize.define('bills',{
    id:{
        type:Sequelize.INTEGER,
        primaryKey: true,
        autoIncrement: true,
        comment:'账单id',
    },
    total_fee:{
        type:Sequelize.INTEGER,

        comment:'支付金额',
    },
    cash_fee:{
        type:Sequelize.INTEGER,
        comment:'实付金额',
    },
    bank_type:{
        type:Sequelize.STRING,
        comment:'支付银行'
    },
    out_trade_no:{
        type:Sequelize.STRING,
        comment:'支付单号',
    },
    time_end:{
        type:Sequelize.STRING,
        comment:'支付时间',
    },
    trade_state_desc:{
        type:Sequelize.STRING,
        comment:'支付状态描述'
    },
    app_id:{
        type:Sequelize.STRING,
        comment:'支付openid'
    },
    mch_id:{
        type:Sequelize.STRING,
        comment:'mch_id'
    },
    tag:{
        type:Sequelize.STRING,
        defaultValue:'微信付款',
        comment:'标签'
    },
    return_code:{
        type:Sequelize.STRING,
        comment:'支付返回码'
    },
    taskid:{
        type:Sequelize.INTEGER,
        defaultValue:null,
        comment:'支付的任务id'
    }
},{
    // freezeTabelName 为 true 时不会在库中映射表时增加复数表名
    // 该选项为 true 时，user 在映射时映射成 user，而为 false 时会映射成users
    freezeTableName: true,
})
UserInfo.belongsTo(User,{foreignKey: "uid"});
User_info_pre.belongsTo(User,{foreignKey: "uid"});
Education_bg.belongsTo(User,{foreignKey: "uid"});
Job.belongsTo(User,{foreignKey: "uid"});
Skill.belongsTo(User,{foreignKey: "uid"});
Opus.belongsTo(User,{foreignKey: "uid"});
Bills.belongsTo(User,{foreignKey: "uid"});

// Skill.belongsToMany(User, {through : 'userSkill'});
//这会创建一个新模型UserProject,其中projectId和userId两个外键。定义through选项后，Sequelize会尝试自动生成名字。
//在本例中，会为User添加方法getUsers,setUsers,addUser,addUsers到Project中。getProjects,setProjects,addProject,addProjects到User中.

let user = User.sync();
let user_info = UserInfo.sync();
let user_info_pre = User_info_pre.sync();
let education_bg = Education_bg.sync();
let job = Job.sync();
let skill = Skill.sync();
let opus = Opus.sync();
let bills = Bills.sync();

exports.User = User
exports.UserInfo = UserInfo
exports.User_info_pre = User_info_pre
exports.Education_bg = Education_bg
exports.Job = Job
exports.Skill = Skill
exports.Opus = Opus
exports.Bills = Bills

